package com.example.cartmanage.chewei.model

import androidx.lifecycle.MutableLiveData
import com.example.cartmanage.bean.CartListEntity
import com.example.cartmanage.chewei.entity.AddCheweiitem
import com.example.cartmanage.chewei.entity.CheweiEntityItem
import com.example.cartmanage.chewei.entity.SearchCheweiEntity
import com.example.cartmanage.chewei.entity.SearchCheweiEntityItem
import com.example.lib_base.mvvm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class CheweiViewModel @Inject constructor(private val repo: CheweiRepo) : BaseViewModel() {
    val CartListSuccess = MutableLiveData<MutableList<CheweiEntityItem>>()
    fun cartList(areaId:Int) {
        httpRequest({ repo.apiService.getcheweiList(areaId) }, { CartListSuccess.postValue(it) })
    }
    // 添加车
    val addCheweiSuccess = MutableLiveData<AddCheweiitem>()
    fun addChewei(map: Map<String,Any>) {
        httpRequest({ repo.apiService.addChewei(repo.mapTopBody( map)) }, { addCheweiSuccess.postValue(it) })
    }
    // 删除车
    val delCheweiSuccess = MutableLiveData<Boolean>()
    fun delChewei(id: Int) {
        httpRequest({ repo.apiService.delChewei(id) }, { delCheweiSuccess.postValue(it) })
    }
    //详情
    val detailcheweiSuccess= MutableLiveData<CheweiEntityItem>()
    fun detailChewei(id: Int) {
        httpRequest({ repo.apiService.detailChewei(id) }, { detailcheweiSuccess.postValue(it) })
    }
    //修改
    val editCheweiSuccess = MutableLiveData<CheweiEntityItem>()
    fun editChewei(id: Int,map:CheweiEntityItem) {
        httpRequest({ repo.apiService.editChewei(id,repo.mapTopBody( map)) }, { editCheweiSuccess.postValue(it) })
    }
    //搜索
    val searchCheweiSuccess = MutableLiveData<SearchCheweiEntity>()
    fun searchChewei(spaceStatus: String) {
        httpRequest({ repo.apiService.searchChewei(spaceStatus) }, { searchCheweiSuccess.postValue(it) })
    }
    val searchCheweiTypeSuccess = MutableLiveData<SearchCheweiEntity>()
    fun searchCheweiType(spaceType: String) {
        httpRequest({ repo.apiService.searchCheweiType(spaceType) }, { searchCheweiTypeSuccess.postValue(it) })
    }
    val searchCheweiLicenseSuccess = MutableLiveData<SearchCheweiEntity>()
    fun searchCheweiLicense(licensePlate: String) {
        httpRequest({ repo.apiService.searchCheweiLicense(licensePlate) }, { searchCheweiLicenseSuccess.postValue(it) })
    }
}